dnl -*- mode: Autoconf; -*-

dnl -----------------------------------------------------------------------------------------
dnl option for static programs
dnl
dnl Note that you need static system libraries 
dnl -----------------------------------------------------------------------------------------

AC_ARG_ENABLE(static-programs,
  AS_HELP_STRING([--enable-static-programs], [do not use shared libraries (default: no)]),
  tr_STATIC_PROGRAMS="$enableval",
  tr_STATIC_PROGRAMS="no"
)

dnl -----------------------------------------------------------------------------------------
dnl enable static programs if possible
dnl -----------------------------------------------------------------------------------------

if test "x$tr_STATIC_PROGRAMS" = xyes;  then
  LDFLAGS="-static"
fi

dnl -----------------------------------------------------------------------------------------
dnl static library
dnl
dnl usage: TR_STATIC_LIBRARY(static-if-name,
dnl                          library environment)
dnl -----------------------------------------------------------------------------------------

AC_DEFUN([TR_STATIC_LIBRARY],[
  if test "x$tr_static_$1" = xyes -a "x$2" != x;  then
    tr_libs=""
    tr_special=""

    for tr_lib in $$2;  do
       case $tr_lib in
         -lpthread|-lm|-lrt)
           tr_special="$tr_special $tr_lib"
           ;;

	 -l*)
	   tr_libs="$tr_libs $tr_lib"
           ;;

         *)
	   tr_libs="$tr_libs $tr_lib"
           ;;
       esac
    done

    $2="$STATIC_LIBS $tr_libs $DYNAMIC_LIBS $tr_special"
  fi
])

dnl -----------------------------------------------------------------------------------------
dnl informational output
dnl -----------------------------------------------------------------------------------------

if test "x$tr_STATIC_PROGRAMS" = xyes;  then
  BASIC_INFO="$BASIC_INFO|STATIC PROGRAMS:  enabled"
else
  BASIC_INFO="$BASIC_INFO|STATIC PROGRAMS:  disabled"
fi
